var pageNow=1;
SPA_RESOLVE_INIT = function(transition) {
    var html = '<table class="Table_common homeworksListTab mt-20">\n' +
        '<thead>\n' +
        '<tr>\n' +
        '<td>id</td>\n' +
        '<td>标题</td>\n' +
        '<td>状态</td>\n' +
        '<td>时间</td>\n' +
        '<td>类型</td>\n' +
        '<td>操作</td>\n' +
        '</tr>\n' +
        '</thead>\n' +
        '<tbody id="taskListTables">\n' +
        '</tbody>\n' +
        '</table> \n' +
        '<div class="paging-area-box mt-10 magin-auto">\n' +
        '<div class="paging-area float-left" id="pagination"></div>\n' +
        '<span class="pageNum float-right f-14">共<em>0</em>条数据</span>\n' +
        '</div>';

    html += '<style>\n' +
        ' \n' +
        ' .homeworksListTab tr td:nth-child(2),\n' +
        ' .homeworksListTab tr td:nth-child(4){\n' +
        'border-left:1px solid #333;\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '.homeworksListTab tr td:nth-child(6){\n' +
        'border-left:1px solid #333;\n' +
        '}\n' +
        '</style>';

    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(3).show();

    document.getElementById("ui-right-content").innerHTML = html;

    homeworkListFun(pageNow);

}

function homeworkListFun(pageNo){
    var id = window.document.getElementById("taskListTables");

    $.ajax({
        url: get_homeworkLlist_interface+'?currentPage='+pageNo,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            currentPage:pageNo
        },
        success: function(data) {
            if(data.code==200){
                inner_homeworkListTbody(data,id, homeworkListFun);
                console.log(data.data)
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function inner_homeworkListTbody(data,id, func){
    var page = data.data.num;
    var currentPage = data.data.currentPage;
    var tml = "";
    $(".pageNum em").html(page);
    if(page>0){
        setPagination(page,currentPage, func);
        pageNow=currentPage;
        var lists = data.data.list;
        $('#pagination').show();
        for (var x=0; x< lists.length;x++) {
            tml += "<tr>"+
                "<td>"+lists[x]["homework_id"]+"</td>"+
                '<td>'+lists[x]["homework_title"]+'</td>'+
                "<td>"+lists[x]["state"]+"</td>"+
                "<td>"+lists[x]["start_time"]+" — "+lists[x]["end_time"]+"</td>"+
                "<td>"+lists[x]["type"]+"</td>"+
                '<td><a href="javascript:;" class="c-009 f-14" onclick="hrefupdate(this)" data-homeworkId="'+lists[x]["homework_id"]+'">编辑</a> / ' +
                '<a href="javascript:;" class="c-009 f-14" onclick="deleteHomeId(this)" data-homeworkId="'+lists[x]["homework_id"]+'">删除</a></td>'+
                "</tr>" ;
        }
    }else{
        $('#pagination').hide();
    }
    id.innerHTML = tml;
}


/**删除***/
function deleteHomeId(obj){
    var homeworkId = $(obj).attr("data-homeworkId");
    $.ajax({
        url: delete_homework_interface,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            homeworkId:homeworkId
        },
        success: function(data) {
            if(data.code==200){
                $.message("删除成功");
                homeworkListFun(pageNow)
            }else{
                parent.popMessage(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}


function hrefupdate(obj) {
    var homeworkId = $(obj).attr("data-homeworkId");
    location.href="?homeworkId="+homeworkId.toString()+"#/updatehomework"
}
